﻿package code 
{
	
	import flash.display.MovieClip;
	import flash.utils.getDefinitionByName;
	import flash.utils.getQualifiedClassName;
	import flash.display.DisplayObject;
	
	// Base class for any dynamic element in the game
	public class GameObject extends MovieClip
	{
	
		// X Velocity
		protected var vx:Number;
		// Y Velocity
		protected var vy:Number;
		// Rotational Velocity
		protected var vr:Number;

		// Default constructor
		public function GameObject() 
		{
			super();
			
			vx = 0;
			vy = 0;
			vr = 0;
		}
		
		// Default update command for a GameObject
		public function update():void
		{
			this.move();
		}
		
		// Default function for moving a GameObject
		// Increments position by velocity
		public function move():void
		{
			this.x += vx;
			this.y += vy;
			this.rotation += vr;
		}
		
		public function destroy():void
		{
			var child:DisplayObject;
			for (var i:int = this.numChildren - 1; i > 0; i--)
			{
				child = this.getChildAt(i);
				
				if (child is EnemyWeapon)
				{
					(child as EnemyWeapon).cleanup();
				}
				
				this.removeChild(child);
			}
		}

		// Returns the class of the object extending GameObject
		public function getClass():Class
		{
			return Class(getDefinitionByName(getQualifiedClassName(this)));
		}
	}
	
}
